@extends('layouts.layouts')
@section('title')
    <title>后台首页</title>
@endsection
@section('content')
    <div class="content">
        <div class="header">

            <h1 class="page-title">pt后台管理</h1>
            <ul class="breadcrumb">
                <li>用户管理</li>
                <li class="active">列表</li>
                 <!-- <li class="active">标签列表</li> -->
            </ul>

        </div>
        <div class="main-content">
            <div class="btn-toolbar list-toolbar">
                <form class="form-inline" action="" method="get">
                   <!--  <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" ><i class="fa fa-plus"></i> 标签</button> -->
                      <div class="form-group">
                        <input type="text" class="form-control" name="id" placeholder="用户编号">
                      </div>
                      <div class="form-group">
                        <input type="text" class="form-control" name="name" placeholder="用户昵称">
                      </div>
                      <div class="form-group">
                        <input type="text" class="form-control" name="mobile" placeholder="用户手机号">
                      </div>
                      <div class="form-group">
                        <select class="form-control" name="status">
                          <option value="">状态全部</option>
                          <option value="1">正常</option>
                          <option value="0">已封禁</option>
                        </select>
                      </div>
                      <button type="submit" class="btn btn-default">筛选</button>
                </form>
            </div>

            <div class="row">
                <div class="col-sm-12 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading no-collapse">标签列表<!-- <span class="label label-warning">+10</span> --></div>
                        <table class="table table-bordered table-striped">
                          <thead>
                            <tr>
                              <th width="5%">编号</th>
                              <th width="5%">用户名</th>
                              <th width="5%">头像</th>
                              <th width="5%">性别</th>
                              <th width="5%">手机号</th>
                              <!-- <th>输出内容</th>
                              <th>输出评论</th> -->
                              <th width="5%">微信昵称</th>
                              <th width="10%">openid</th>
                              <!-- <th width="5%">积分</th> -->
                              <th width="10%">注册时间</th>
                              <th width="5%">状态</th>
                              <th width="10%">操作</th>
                            </tr>
                          </thead>
                          <tbody>
                            @foreach($list as $item)
                            <tr>
                              <td>{{$item->id}}</td>
                              <td>{{$item->name}}</td>
                              <td>
                                @if(strpos($item->avatar,'http') !== false)
                                <img class="pimg" src="{{$item->avatar}}" height="60" alt="微信头像" />
                                @else
                                <img class="pimg" src="{{env('IMG_URL')}}{{$item->avatar}}" height="60" alt="自己上传" />
                                @endif
                              </td>
                              @if($item->sex=='male')
                              <td>男</td>
                              @else
                              <td>女</td>
                              @endif
                              <td>{{$item->mobile}}</td>
                              <!-- <td>{{sum_content($item->id)}}/篇</td>
                              <td>{{sum_comment($item->id)}}/条</td> -->
                              <td>{{$item->nickname}}</td>
                              <td>{{$item->openid}}</td>
                              
                              <!-- <td>{{sum_user_add($item->id)}}/元</td> -->
                              <td>{{$item->created_at}}</td>
                              <td>
                                @if($item->status==0)
                                <span class="label label-success">正常</span>
                                @else
                                <span class="label label-danger">已封禁</span>
                                @endif 
                              </td>
                              <td>
                                <a href="/user/userdetail/{{$item->id}}">查看</a>
                                @if($item->status==0)
                                <a class="user_status" id="user_status{{$item->id}}" data-id="{{$item->id}}" data-status="1" href="javascript:;">封禁</a>
                                @else
                                 <a class="user_status" id="user_status{{$item->id}}" data-id="{{$item->id}}" data-status="0" href="javascript:;">解封</a>
                                @endif
                                <a href="/user/spb/{{$item->id}}">活动赠送</a>
                                @if(is_fission($item->id) == 0)
                                    <a href="/admin/fission/{{$item->id}}/1">设为裂变者</a>
                                @else
                                    <a href="/admin/fission/{{$item->id}}/0">取消裂变者</a>
                                @endif
                              </td>
                            </tr>
                            @endforeach
                          </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <div class="modal small fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                            <h3 id="myModalLabel">Delete Confirmation</h3>
                        </div>
                        <div class="modal-body">
                            <p class="error-text"><i class="fa fa-warning modal-icon"></i>Are you sure you want to delete the user?<br>This cannot be undone.</p>
                        </div>
                        <div class="modal-footer">
                            <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cancel</button>
                            <button class="btn btn-danger" data-dismiss="modal">Delete</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script type="text/javascript">
        $(document).ready(function(){
            //提交信息
            $(".user_status").click(function(){
                var id     = $(this).attr("data-id");        //被操作的记录id
                var status = $(this).attr("data-status");    //被修改的状态
                var classid= "user_status"+id;            
                var text   = status==1 ? '解封' : "封禁";    //修改后的操作文字
                var statust= status==1 ? '已封禁' : "正常";  //修改后的状态文字
                var css    = status==1 ? 'label label-danger' : "label label-success";   //修改后css样式
                var newstatus = status==1 ? 0 : 1;           //修改后更新的状态

                $.ajax({
                    type:"get",
                    url:"/user/upstatus",
                    data:{id:id, status:status},
                    dataType:'json',
                    success:function(result){
                        if(result.code==1){
                            $("#"+classid).html(text);
                            $("#"+classid).attr('data-status', newstatus);
                            $("#"+classid).parent().prev().children().attr("class", css).text(statust);
                        }else{
                             alert(result.msg);
                        }
                    }
                });
            });
        })
    </script>
@endsection